﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace d39
{
    public abstract class GridCommand
    {
        protected GridCommand(GridPage page)
        {
            this.GridPage = page;
        }

        [NonSerialized]
        private GridPage gridPage;
        protected internal GridPage GridPage { get { return gridPage; } internal set { gridPage = value; } }

        protected Grid CurrentGrid { get { return GridPage.CurrentGrid; } }

        /// <summary>
        /// Text for display. "{}" gets replaced by current coordinate.
        /// </summary>
        public abstract string Text { get; }

        /// <summary>
        /// Which cells it applies in, or null for applying everywhere
        /// </summary>
        public virtual IEnumerable<HalfCoordinate> Cells { get { yield break; } }

        public abstract void Invoke(HalfCoordinate coord);

        public string CellsStr
        {
            get { return Cells.Any() ?  string.Join(" ", from cell in Cells select "cell-" + cell.ToHumanReadableString().Replace('+', '-')) : "allcells"; }
        }
    }
}